package xyz.huanggy.minio.upload.model.dto;

import cn.hutool.core.bean.BeanUtil;
import io.minio.messages.Part;
import lombok.Data;
import lombok.ToString;
import lombok.experimental.Accessors;
import org.springframework.beans.BeanUtils;
import xyz.huanggy.minio.upload.model.entity.SysFileInfo;

import java.util.List;
import java.util.stream.Collectors;

@Data
@ToString
@Accessors(chain = true)
public class TaskRecordDTO extends SysFileInfo {

    /**
     * 已上传完的分片
     */
    private List<FilePart> exitPartList;


    public void setExitPartList(List<Part> exitPartList) {
        if (exitPartList != null) {
            this.exitPartList = exitPartList.stream().map(item -> {
                FilePart part = new FilePart();
                part.setPartNumber(item.partNumber());
                part.setSize(item.partSize());
                return part;
            }).collect(Collectors.toList());
        }

    }

    public static TaskRecordDTO convertFromEntity(SysFileInfo task) {
        TaskRecordDTO dto = new TaskRecordDTO();
        BeanUtil.copyProperties(task, dto);
        return dto;
    }
}
